﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using AnyOffice.DAL;
using System.Data;
using AnyOffice.Components;
using System.Data.SqlClient;
using AnyOffice.Model;

namespace AnyOffice
{
    /// <summary>
    /// Map 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消对下行的注释。
    [System.Web.Script.Services.ScriptService]
    public class Map : System.Web.Services.WebService
    {

        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }

        [WebMethod]
        public string GetMapPos(int mapType)
        {
            SqlConnection conn = new SqlConnection(ConfigManager.ConnectionString);
            string returnStr = string.Empty;
            DataTable tbl = new MapInfoDao().SelectByMapType(conn, mapType);
            foreach (DataRow item in tbl.Rows)
            {
                returnStr += (item["MapID"].ToString() + "," + item["Name"] + "," + item["Address"] + "," + item["Longitude"] + "," + item["Latitude"] + "," + item["MapType"] + "|");
            }
            return returnStr;
        }


        [WebMethod]
        public string DelMap(string mapid)
        {
            SqlConnection conn = new SqlConnection(ConfigManager.ConnectionString);

            if (new MapInfoDao().Delete(conn, int.Parse(mapid)))
                return "删除成功";
            return "删除失败";



        }
        [WebMethod]
        public string UpdateMap(string mapid, string mapType, string name, string address, string longitude, string latiude)
        {
            SqlConnection conn = new SqlConnection(ConfigManager.ConnectionString);
            MapData data = new MapData();

            data.MapType = int.Parse(mapType);
            data.Name = name;
            data.Address = address;
            data.Longitude = double.Parse(longitude);
            data.Latitude = double.Parse(latiude);
            if (string.Empty.Equals(mapid))
            {
                if (new MapInfoDao().Insert(conn, data) >= 0)
                    return "保存成功";
                return "保存失败";
            }
            else
            {
                data.MapId = int.Parse(mapid);
                if (new MapInfoDao().Update(conn, data))
                    return "保存成功";
                return "保存失败";
            }


        }
    }
}
